package logic

import (
	"context"
	"doc-manage/model/mysql"
	"errors"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocDetailLogic {
	return &DocDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *DocDetailLogic) DocDetail(in *docrpc.DocDetailRequest) (*docrpc.DocDetailResponse, error) {
	// todo: add your logic here and delete this line

	var doc mysql.Doctor

	err := doc.DocDetail(mysql.DB, in.DoctorId)
	if err != nil {
		return nil, errors.New("展示详情列表失败")
	}

	return &docrpc.DocDetailResponse{
		DoctorId: int64(doc.ID),
		Username: doc.Username,
		Tel:      doc.Tel,
		Address:  doc.Address,
	}, nil
}
